#include <bits/stdc++.h>
using namespace std;

int n, a[1001], prefix[1001];

int main()
{
	freopen("bcount.in","r",stdin);
	freopen("bcount.out","w",stdout);
	cin>>n;

	for(int i=1; i<=n; i++)
	{
		cin>>a[i];
		//todo
		prefix[i]=prefix[i-1]+a[i];
	}
		
	int ans = INT_MIN;
	for(int i=1;i<=n;i++) //begin location
	{
		for(int j=i;j<=n;j++)  //end location
		{
			ans=max(ans,prefix[j]-prefix[i-1]);
		}
	}
	

	cout<<ans<<endl;
	
	return 0;	
}

//5
//1 -2 3 1 -4


